package org.lyimg.com.imgapplication.RetrofitHelper;

import android.content.Context;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;


public class RetrofitHelper {
    private Context mCntext;

    OkHttpClient.Builder builder = new OkHttpClient.Builder();

//    GsonConverterFactory factory = GsonConverterFactory.create(new GsonBuilder().create());//json解析 直接返回实体类
    private static RetrofitHelper instance = null;
    private Retrofit mRetrofit = null;
    public static RetrofitHelper getInstance(Context context){
        if (instance == null){
            instance = new RetrofitHelper(context);
        }
        return instance;
    }
    private RetrofitHelper(Context mContext){
        mCntext = mContext;
        init();
    }

    private void init() {
        resetApp();
    }

    private void resetApp() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl("https://api.douban.com/v2/")
                .client(builder.build())
//                .addConverterFactory(factory)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }
    public HttpRetrofitService getServer(){
        return mRetrofit.create(HttpRetrofitService.class);
    }
}
